package com.cetc.sdp.mzga.service.conf;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.io.FileUtils;

public class DBConf {
	  private static Properties properties = new Properties();
	  
	  private static DBConf instance;
	  private DBConf() {}
	  public static synchronized DBConf getInstance() throws IOException {
	    if (null == instance) {
	      instance = new DBConf();
	    }
	    
	    instance.loadConfig();
	    
	    return instance;
	  }
	  
	  private final static String PATH = "druid-phoenix.properties";

	  public void loadConfig() throws IOException {
	    InputStream in = DBConf.class.getClassLoader().getResourceAsStream(PATH);
	    properties.load(in);
	  }
	  
	  public void loadConfig(String config) throws IOException {
	    String conf = FileUtils.readFileToString(new File(config), "UTF-8");
	    
	    properties.load(new ByteArrayInputStream(conf.getBytes()));
	  }

	  public String getValue(String key) {
	    return properties.getProperty(key);
	  }
	  
	  public String getValue(String key, String defaultValue) {
	    return properties.getProperty(key, defaultValue);
	  }
	  
	  public Properties getProperties(){
		  return properties;
	  }
	  

}

